﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace HPPClientLibrary.DownLoad
{
    public class TimerJob
    {
        private Action<IPEndPoint> _getPeerList;
        private Action _clearDisableIPList;
        private int _getPeerListCurrentTime;
        private int _clearDisableIPListCurrentTime;

        public TimerJob()
        {
            
        }
        public TimerJob(Action<IPEndPoint> getPeerList,Action clearDisableIPList)
        {
            _getPeerList = getPeerList;
            _clearDisableIPList = clearDisableIPList;
        }


        public Action<IPEndPoint> GetPeerList
        {
            set
            {
                _getPeerList = value;
            }
            get
            {
                return _getPeerList;
            }
        }

        public Action ClearDisableIPList
        {
            set
            {
                _clearDisableIPList = value;
            }
            get
            {
                return _clearDisableIPList;
            }
        }
        public bool IsGetPeerListOnTime(int addTime,int getPeerListInterval)
        {
            _getPeerListCurrentTime += addTime;
            if (_getPeerListCurrentTime >= getPeerListInterval )
            {
                _getPeerListCurrentTime = 0;
                return true;
            }
            return false;
        }
        public bool IsClearDisableIPListOnTime(int addTime,int clearDisableIPListInterval)
        {
            _clearDisableIPListCurrentTime += addTime;
            if (_clearDisableIPListCurrentTime >= clearDisableIPListInterval)
            {
                _clearDisableIPListCurrentTime = 0;
                return true;
            }
            return false;
        }
    }
}
